package Generator;



import com.databasedictionary.utils.MybatisGeneratorForOracleUtil;
import com.databasedictionary.utils.PropertiesFileUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 代码生成类
 * Created by Yankees on 2017/4/26.
 */
public class Generator {

    // 根据命名规范，只修改此常量值即可
    private static String MODULE = "";
    private static String proertiesName = "generator-oracle";//配置文件名
    private static String DATABASE = "club_sale"; // ORACLE不需要
    private static String TABLE_PREFIX = "CII"; // 数据库表前缀
    private static String PACKAGE_NAME = "com.databasedictionary.CII";//目录位置
    private static String JDBC_DRIVER = PropertiesFileUtil.getInstance(proertiesName).get("generator.jdbc.driver");
    private static String JDBC_URL = PropertiesFileUtil.getInstance(proertiesName).get("generator.jdbc.url");
    private static String JDBC_USERNAME = PropertiesFileUtil.getInstance(proertiesName).get("generator.jdbc.username");
    private static String JDBC_PASSWORD = PropertiesFileUtil.getInstance(proertiesName).get("generator.jdbc.password");
    // 需要insert后返回主键的表配置，key:表名,value:主键名
    private static Map<String, String> LAST_INSERT_ID_TABLES = new HashMap<>();

    static {

    }

    /**
     * 自动代码生成
     *
     * @param args
     */
    public static void main(String[] args) throws Exception {

        String tableName = "UN_CII_T_002_TASK";
        String sql = "insert into " + tableName  +" ( ";
        sql += " UN_CII_002_MAIN_ID, UN_CII_002_TASK_NAME, UN_CII_002_INFO, UN_CII_002_STATUS, UN_CII_002_COUTENT, UN_CII_002_START_TIME, UN_CII_002_END_TIME,";
        sql = sql.substring(0, sql.length() - 1);
        sql += ") values( ";
        sql += " ?, ?, ?, ?, ?, ?, ?,";
        sql = sql.substring(0, sql.length() - 1);
        sql += ") ";


        System.out.println(sql);

        //生成所有
//        MybatisGeneratorForOracleUtil.generator(JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD, MODULE, DATABASE, TABLE_PREFIX, PACKAGE_NAME, LAST_INSERT_ID_TABLES);
//        List<Map<String, Object>> tables = MybatisGeneratorUtil.selectTable(JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD, MODULE, DATABASE, TABLE_PREFIX, PACKAGE_NAME, LAST_INSERT_ID_TABLES);
        //查询所有表
        //生成Dao层
//        MybatisGeneratorUtil.createDao();
        //生成rpc-service、rcp-api、common
//        MybatisGeneratorUtil.createService(tables);
        //生成Api层
        //MybatisGeneratorUtil.createApi(tables);
        //生成Adin管理后台
//        MybatisGeneratorUtil.createAdmin(tables);
    }

}
